home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_dial2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  3.6 KB  |  169 lines

  1. # include  <stdio.h>
  2. # include  "d_returns.h"
  3.  
  4.  
  5. /*
  6.  *     D_CHKACCESS
  7.  *
  8.  *     this routine checks for the user name given as the argument string
  9.  *     in the access file given as the second argument.
  10.  *
  11.  *     username -- the user's name that we're looking for
  12.  *
  13.  *     accessfile -- path name of the access file.  this file has one user name
  14.  *                   per line
  15.  */
  16.  
  17. d_chkaccess(username, accessfile)
  18. char  *username, *accessfile;
  19. {
  20.     extern int  d_errno;
  21. #ifdef D_LOG
  22.     register int  linenum = 0;
  23. #endif D_LOG
  24.     register int  length;
  25.     char  *fields[1], linebuf[128];
  26.     FILE  *accfp;
  27.  
  28. #ifdef D_DBGLOG
  29.     d_dbglog("d_chkaccess", "user %s accessfile %s", username, accessfile);
  30. #endif D_DBGLOG
  31.  
  32. /*  open the access list file.  if we can't, just return quietly  */
  33.  
  34.     if ((accfp = fopen(accessfile, "r")) == NULL)
  35.       return(0);
  36.  
  37.     while (fgets(linebuf, sizeof linebuf - 1, accfp) != NULL)
  38.     {
  39. #ifdef D_LOG
  40.     linenum++;
  41. #endif D_LOG
  42. /*  make sure we got the whole line  */
  43.     length = strlen(linebuf);
  44.     if (linebuf[length - 1] != '\n')
  45.     {
  46. #ifdef D_LOG
  47.             d_log("d_chkaccess", "access file '%s', line %d too long",
  48.         accessfile, linenum);
  49. #endif D_LOG
  50.         d_errno = D_ACCERR;
  51.         return(D_FATAL);
  52.         }
  53.  
  54. /*  parse the line  */
  55.  
  56.       switch (d_linparse(fields, linebuf, 1))
  57.         {
  58.         case  0:
  59.             continue;
  60.  
  61.         case  1:
  62.             if (strcmp(username, fields[0]) == 0)
  63.               {
  64.           fclose(accfp);
  65.               return(D_OK);
  66.               }
  67.             continue;
  68.  
  69.         case  -1:
  70. #ifdef D_LOG
  71.             d_log("d_chkaccess", "access file '%s', line %d: too many fields",
  72.                 accessfile, linenum);
  73. #endif D_LOG
  74.             d_errno = D_ACCERR;
  75.             return(D_FATAL);
  76.  
  77.         case  -2:
  78. #ifdef D_LOG
  79.             d_log("d_chkaccess",
  80.                 "access file '%s', line %d: qupted string too long", accessfile,
  81.                 linenum);
  82. #endif D_LOG
  83.             d_errno = D_ACCERR;
  84.             return(D_FATAL);
  85.  
  86.         default:
  87. #ifdef D_LOG
  88.             d_log("d_chkaccess", "access file '%s', line %d: unknown error",
  89.                 accessfile, linenum);
  90. #endif D_LOG
  91.             d_errno = D_ACCERR;
  92.             return(D_FATAL);
  93.         }
  94.       }
  95.  
  96. #ifdef D_DBGLOG
  97.     d_dbglog("d_chkaccess", "name not found");
  98. #endif D_DBGLOG
  99.     fclose(accfp);
  100.     return(D_NO);
  101.  
  102. }
  103.  
  104.  
  105. /*
  106.  *     D_TYPELIST
  107.  *
  108.  *     this routine returns a list of acceptable dial port types based on the
  109.  *     given phone number.  
  110.  *
  111.  *     Currently, the type is gotten out of the phone number and the
  112.  *     phone number is munged to exclude the type field.
  113.  *
  114.  *     numptr -- pointer to the phone number being called
  115.  *      
  116. */
  117.  
  118. char **
  119. d_typelist(numptr)
  120.   char  **numptr;
  121.     {
  122.  
  123.     extern char *strdup ();
  124.     char tempbuf[25];
  125.     char *tpt, *newnum, *number;
  126.     static char *typelist[] = {
  127.         "LOCAL",
  128.     0
  129.         };
  130.  
  131.     tpt = tempbuf; 
  132.     number = *numptr;
  133.     newnum = number;
  134.  
  135. #ifdef D_DBGLOG
  136.     d_dbglog("d_typelist", "number %s", *numptr);
  137. #endif D_DBGLOG
  138.  
  139.     if (d_instring('<', number) != 0)
  140.        {
  141.        while (*number)
  142.           if (*number != '<')
  143.              *newnum++ = *number++;
  144.           else
  145.              { /* pick off type */
  146.              while (*++number != '>')
  147.                 *tpt++ = *number; 
  148.              number++;
  149.              }
  150.  
  151.        *newnum = '\0';
  152.        }
  153.  
  154.     *tpt = '\0';
  155.  
  156. #ifdef D_DBGLOG
  157.     d_dbglog("d_typelist", "new number %s", *numptr);
  158. #endif D_DBGLOG
  159.  
  160.     if (tempbuf[0] != '\0')
  161.        typelist[0] = strdup(tempbuf);
  162.  
  163. #ifdef D_DBGLOG
  164.     d_dbglog("d_typelist", "returning type %s", typelist[0]);
  165. #endif D_DBGLOG
  166.  
  167.     return(typelist);
  168. }
  169.